import { useLoginStore } from '../store/login'

const loginStore = useLoginStore()
const { isShowImgCode } = storeToRefs(loginStore)

/** 表单规则 */
export const formRule = {
  loginName: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
  password: [{ required: true, message: '请输入登录密码', trigger: 'blur' }],
  verifyCode: [
    {
      validator: (_, value, callback) => {
        if (isShowImgCode && !value) {
          return callback(new Error('请输入验证码'))
        } else {
          callback()
        }
      },
      trigger: 'blur',
    },
  ],
}
